/****************************************************************************************************
 ** @file       TS101Common.c
 ** @brief      
 ** @details
 **   
 ** @copyright  S7501
 ** @author     yss93
 ** @date       2021/10/11
 **************************************************************************************************/

#include <builtins.h>
#include <defts101.h>
#include <sysreg.h>

#include "../common/allCommon.h"
#include "TS101Common.h"
PRIVATE volatile INT32 _tmpIMASK = 0;

PUBLIC INT32 TSREG_SetIMASKL(INT32 bits){
    _tmpIMASK = __builtin_sysreg_read(__IMASKL);
    _tmpIMASK = _tmpIMASK | bits;
    __builtin_sysreg_write(__IMASKL, _tmpIMASK);
    return ERROR_NONE;
}

PUBLIC INT32 TSREG_ClearIMASKL(INT32 bits){
    _tmpIMASK = __builtin_sysreg_read(__IMASKL);
    _tmpIMASK = _tmpIMASK | ~(bits);
    __builtin_sysreg_write(__IMASKL, _tmpIMASK);
    return ERROR_NONE;
}

PUBLIC INT32 TSREG_SetIMASKH(INT32 bits){
    _tmpIMASK = __builtin_sysreg_read(__IMASKH);
    _tmpIMASK = _tmpIMASK | bits;
    __builtin_sysreg_write(__IMASKH, _tmpIMASK);
    return ERROR_NONE;
}

PUBLIC INT32 TSREG_ClearIMASKH(INT32 bits){
    _tmpIMASK = __builtin_sysreg_read(__IMASKH);
    _tmpIMASK = _tmpIMASK | bits;
    __builtin_sysreg_write(__IMASKH, _tmpIMASK);
    return ERROR_NONE;
}

PUBLIC INT32 TSREG_SetIMASK_GIE(void){
    return TSREG_SetIMASKH(INT_GIE);
}
